#include "linkstack.h"

int main(void)
{
	/*创建空链栈*/
	pstack top,pnew;
	creat_linkstack(&top);
	
	/*向链栈中插入若干节点*/
	int result,n;
	
	while(1)
	{
		pnew = (pstack)malloc(sizeof(STACK));
		if (pnew == NULL)
		{
			perror("malloc");
			return 1;
		}
		
		printf("请输入任意数据。若输入整数则入栈；若输入非整数则出栈；若输入-1则结束输入：");
		result = scanf("%d",&(pnew->data));
		
		if(result == 1)//若输入了整数
		{
			if(pnew->data == -1)	break;
			else
			{
				push(&top,pnew);
				print_linkstack(top);
			}
		}
		else
		{
			pop(&top,&n);
			//printf("出栈：%d\n",n);
			print_linkstack(top);
			while(getchar() != '\n'); //清空缓冲区
		}
	}
	
	return 0;
}